/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * insumos_salidas_agregar.java
 *
 * Created on 6/04/2011, 10:48:38 AM
 */

package sie_invdis;



import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;

import java.text.ParseException;
/**
 *
 * @author Michelle
 */
public class insumos_salidas_agregar extends javax.swing.JDialog {

    private javax.swing.table.DefaultTableModel jtable_modelo;
    private bd_conexion x = new bd_conexion() ;
       //se creaa la variable resultset
      private ResultSet rs = null;
      int controlcombo=0;
    /** Creates new form insumos_salidas_agregar */
    public insumos_salidas_agregar(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
         //x.estableceConexion();
        this.iniciar_modelo_de_tabla();
        initComponents();
        this.setLocation(100,25);
        java.util.Date fechahoya=new Date();
        this.jdc_fechadocto.setDate(fechahoya);
        this.loadcombo();
        this.cargar_insumos(3);

        jtb_insumos.getColumnModel().getColumn(0).setPreferredWidth(70);//cantidad
        jtb_insumos.getColumnModel().getColumn(1).setPreferredWidth(220);//codigo
        jtb_insumos.getColumnModel().getColumn(2).setPreferredWidth(40);//descripcion.
        jtb_insumos.getColumnModel().getColumn(3).setPreferredWidth(30);//descripcion.
        jtb_insumos.getColumnModel().getColumn(4).setPreferredWidth(60);//descripcion.
        jtb_insumos.getColumnModel().getColumn(5).setPreferredWidth(120);//descripcion.
        this.loadcombodepa();
        this.loadcombocliente();
        this.loadcomalmacenes();
        this.loadcomboempleados();
    }

  private void loadcombo(){
     
       rs = x.sieuno_executediversosv2("select * from x1distribucion_insumos_tipos() as (id smallint,cla character varying(40));",variables_global.getconexiongral());
       this.jcbx_tiposinsumos.addItem("3"+":"+"Limpieza");
       try
         {
            while (rs.next())
                {
                            this.jcbx_tiposinsumos.addItem(rs.getString("id")+":"+rs.getString("cla"));
                }

        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
        
         
        
    }
  private void loadcombodepa()
  {
          this.jcmbx_depa.addItem(variables_global.getdepartamento()+":"+variables_global.getdepartamento_des());
          rs = x.sieuno_executediversosv2("select * from x1_supervision_tareas_departamentos() as (id smallint,descrip character varying(80));",variables_global.getconexiongral());
            try
            {

               while (rs.next())
                    {
                      this.jcmbx_depa.addItem(rs.getString("id")+":"+rs.getString("descrip"));
                    }
             }
            catch(Exception e)
            {
                System.out.println(e.getMessage());
            }
    }
  private void loadcomalmacenes()
    {
          this.jcmbx_almacenes.addItem(variables_global.getalmacen()+":"+variables_global.getalmacen());
          rs = x.sieuno_executediversosv2("select * from x1distribucion_insumos_almacenes() as (id smallint,cla character varying(30));",variables_global.getconexiongral());
            try
            {

               while (rs.next())
                    {
                      this.jcmbx_almacenes.addItem(rs.getString("id")+":"+rs.getString("cla"));
                     

                    }
             }
            catch(Exception e)
            {
                System.out.println(e.getMessage());
            }



    }
  private void loadcomboempleados(){

       int opcion=0;
       String textobuscaemplea="";
          this.jcbx_empleados.addItem("0:Seleccione Empleado");
        if (variables_global.getnivelusu()==3)
            {
                textobuscaemplea=String.valueOf(variables_global.getdepartamento());
                opcion=1;
            }
          
        rs = x.sieuno_executediversosv2("select * from x1_supervision_empleados("+opcion+",'"+textobuscaemplea+"') as (id integer,nombre text,idtie integer,iddepa smallint,idpuesto smallint,idstatus smallint,foto character varying(80),idsieuno integer,descripdep character varying(80),descrippuesto text);",variables_global.getconexiongral());
        try
         {
            while (rs.next())
                {
                    this.jcbx_empleados.addItem(rs.getString("id")+":"+rs.getString("descripdep")+":"+rs.getString("nombre"));
                }
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }


    }
 private void loadcombocliente(){

         
          this.jcmbx_tiendaclie.addItem(variables_global.getcliente_tistribucion()+":"+variables_global.getcliente_tistribucion());
        this.jcmbx_tiendaclie.addItem("all:all");
    }
private void iniciar_modelo_de_tabla()
    {

        jtable_modelo=new javax.swing.table.DefaultTableModel();//Creo el modelo
        jtable_modelo.addColumn("<html><b>Clave</b></html>");
        jtable_modelo.addColumn("<html><b>Descripcion</b></html>");
        jtable_modelo.addColumn("<html><b>Unidad</b></html>");
        jtable_modelo.addColumn("<html><b>Cantidad</b></html>");
        jtable_modelo.addColumn("<html><b>Observaciones</b></html>");
        jtable_modelo.addColumn("<html><b>Foto</b></html>");

    }
private void cargar_insumos(int tipo_elemento)
    {
        this.LimpiarJTable();
        rs = x.sieuno_executediversosv2("select * from x1distribucion_insumos_catalogo(1,0,'"+tipo_elemento+"') as (cla character varying(16),des character varying(80), unsal character varying(3),descritipo character varying(40),orden numeric);",variables_global.getconexiongral());
       try
         {
            while (rs.next())
                {
                    jtable_modelo.addRow(new Object[]{rs.getString ("cla"),rs.getString ("des"),rs.getString("unsal"),0,"",""});
                }

        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
    }

private void carga_datos_asignaempleado(String codigo)
    {
       //invoco al metodo que trae el recordset de datos
    int encontro=0;
    String empleado="",idasigna="";
       rs = x.sieuno_executediversosv2("select * from x1distribucion_insumos_salidas_asignaempleado('"+codigo+"') as (idemp integer,nombre character varying(50),nombreapat character varying(50),nombreamat character varying(50));",variables_global.getconexiongral());
        try
         {
            while (rs.next())
                {
                    encontro=1;
                    idasigna=rs.getString("idemp");
                    empleado=rs.getString("nombre")+" "+rs.getString("nombreapat")+" "+rs.getString("nombreamat");
                }

        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }

       if (encontro==1)
              {
                  if(JOptionPane.showConfirmDialog(null, "<html><h1>Asignado a:"+empleado+" Esta Correcto?</h1><html>")==0)
                        {
                            //this.jtf_asignaid.setText(idasigna);
                           // this.jtf_asignanombre.setText(empleado);
                           // this.jtb_insumos.requestFocus();
                            encontro=0;
                        }
                  else
                        {
                            //this.jpwf_asignaidentifica.requestFocus();
                            //this.jpwf_asignaidentifica.setText("");
                            //this.jtf_asignaid.setText("0");
                            //this.jtf_asignanombre.setText("");
                            encontro=0;
                        }
              }
       else
           {
               //this.jpwf_asignaidentifica.requestFocus();
               //this.jpwf_asignaidentifica.setText("");
               JOptionPane.showMessageDialog(null,"Error No existe el Empleado", "Sistema Integral(Insumos Asignar: Alta) : Ayuda",1);
               encontro=0;
           }
      }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jpn_encabezado = new javax.swing.JPanel();
        jcbx_tiposinsumos = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jtf_observaciones = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jdc_fechadocto = new com.toedter.calendar.JDateChooser();
        jcmbx_tiendaclie = new javax.swing.JComboBox();
        jcmbx_depa = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jcmbx_almacenes = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jcb_verfotos = new javax.swing.JCheckBox();
        jLabel7 = new javax.swing.JLabel();
        jcbx_empleados = new javax.swing.JComboBox();
        jpn_cuerpo = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtb_insumos = new javax.swing.JTable()
        {
            public boolean isCellEditable(int rowIndex, int mColIndex) {
                if (mColIndex < 3)
                return false;
                else
                return true;
            }
        }
        ;
        jPanel1 = new javax.swing.JPanel();
        jbtn_guardar = new javax.swing.JButton();
        jbtn_salir = new javax.swing.JButton();
        jbtn_helpayudame = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jmni_guardaralts = new javax.swing.JMenuItem();
        jmni_guardaorecep = new javax.swing.JMenuItem();
        jmni_salir = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jmni_escape = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jmni_ayuda = new javax.swing.JMenuItem();
        jmni_sugerencias = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        jpn_encabezado.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jpn_encabezado.setName("jpn_encabezado"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sie_invdis.Sie_invdisApp.class).getContext().getResourceMap(insumos_salidas_agregar.class);
        jcbx_tiposinsumos.setFont(resourceMap.getFont("jcbx_tiposinsumos.font")); // NOI18N
        jcbx_tiposinsumos.setName("jcbx_tiposinsumos"); // NOI18N
        jcbx_tiposinsumos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbx_tiposinsumosActionPerformed(evt);
            }
        });

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jtf_observaciones.setText(resourceMap.getString("jtf_observaciones.text")); // NOI18N
        jtf_observaciones.setName("jtf_observaciones"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jdc_fechadocto.setName("jdc_fechadocto"); // NOI18N

        jcmbx_tiendaclie.setName("jcmbx_tiendaclie"); // NOI18N

        jcmbx_depa.setName("jcmbx_depa"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jcmbx_almacenes.setName("jcmbx_almacenes"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jcb_verfotos.setText(resourceMap.getString("jcb_verfotos.text")); // NOI18N
        jcb_verfotos.setToolTipText(resourceMap.getString("jcb_verfotos.toolTipText")); // NOI18N
        jcb_verfotos.setName("jcb_verfotos"); // NOI18N
        jcb_verfotos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcb_verfotosActionPerformed(evt);
            }
        });

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jcbx_empleados.setName("jcbx_empleados"); // NOI18N

        javax.swing.GroupLayout jpn_encabezadoLayout = new javax.swing.GroupLayout(jpn_encabezado);
        jpn_encabezado.setLayout(jpn_encabezadoLayout);
        jpn_encabezadoLayout.setHorizontalGroup(
            jpn_encabezadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpn_encabezadoLayout.createSequentialGroup()
                .addGroup(jpn_encabezadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpn_encabezadoLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcmbx_tiendaclie, 0, 282, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5)
                        .addGap(11, 11, 11)
                        .addComponent(jcmbx_depa, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(73, 73, 73)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jdc_fechadocto, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpn_encabezadoLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcmbx_almacenes, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27)
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(jcbx_tiposinsumos, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcbx_empleados, javax.swing.GroupLayout.PREFERRED_SIZE, 239, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpn_encabezadoLayout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addComponent(jLabel4)
                        .addGap(18, 18, 18)
                        .addComponent(jtf_observaciones, javax.swing.GroupLayout.PREFERRED_SIZE, 367, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jcb_verfotos)))
                .addContainerGap())
        );
        jpn_encabezadoLayout.setVerticalGroup(
            jpn_encabezadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpn_encabezadoLayout.createSequentialGroup()
                .addGroup(jpn_encabezadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpn_encabezadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(jcmbx_tiendaclie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpn_encabezadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jcmbx_depa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel5)
                        .addComponent(jLabel2))
                    .addComponent(jdc_fechadocto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jpn_encabezadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jcmbx_almacenes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(jcbx_tiposinsumos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jcbx_empleados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jpn_encabezadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtf_observaciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jcb_verfotos))
                .addContainerGap(20, Short.MAX_VALUE))
        );

        jpn_cuerpo.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jpn_cuerpo.setName("jpn_cuerpo"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jtb_insumos.setModel(this.jtable_modelo);
        jtb_insumos.setName("jtb_insumos"); // NOI18N
        jScrollPane1.setViewportView(jtb_insumos);

        javax.swing.GroupLayout jpn_cuerpoLayout = new javax.swing.GroupLayout(jpn_cuerpo);
        jpn_cuerpo.setLayout(jpn_cuerpoLayout);
        jpn_cuerpoLayout.setHorizontalGroup(
            jpn_cuerpoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpn_cuerpoLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 820, Short.MAX_VALUE)
                .addContainerGap())
        );
        jpn_cuerpoLayout.setVerticalGroup(
            jpn_cuerpoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpn_cuerpoLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setName("jPanel1"); // NOI18N

        jbtn_guardar.setIcon(resourceMap.getIcon("jbtn_guardar.icon")); // NOI18N
        jbtn_guardar.setText(resourceMap.getString("jbtn_guardar.text")); // NOI18N
        jbtn_guardar.setName("jbtn_guardar"); // NOI18N
        jbtn_guardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_guardarActionPerformed(evt);
            }
        });

        jbtn_salir.setIcon(resourceMap.getIcon("jbtn_salir.icon")); // NOI18N
        jbtn_salir.setText(resourceMap.getString("jbtn_salir.text")); // NOI18N
        jbtn_salir.setName("jbtn_salir"); // NOI18N
        jbtn_salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_salirActionPerformed(evt);
            }
        });

        jbtn_helpayudame.setIcon(resourceMap.getIcon("jbtn_helpayudame.icon")); // NOI18N
        jbtn_helpayudame.setText(resourceMap.getString("jbtn_helpayudame.text")); // NOI18N
        jbtn_helpayudame.setName("jbtn_helpayudame"); // NOI18N
        jbtn_helpayudame.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_helpayudameActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(253, 253, 253)
                .addComponent(jbtn_salir)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 292, Short.MAX_VALUE)
                .addComponent(jbtn_helpayudame)
                .addGap(127, 127, 127))
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jbtn_guardar)
                    .addContainerGap(711, Short.MAX_VALUE)))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jbtn_salir)
                .addComponent(jbtn_helpayudame))
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(2, 2, 2)
                    .addComponent(jbtn_guardar)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        jMenuBar1.setName("jMenuBar1"); // NOI18N

        jMenu1.setText(resourceMap.getString("jMenu1.text")); // NOI18N
        jMenu1.setName("jMenu1"); // NOI18N

        jmni_guardaralts.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_G, java.awt.event.InputEvent.ALT_MASK));
        jmni_guardaralts.setText(resourceMap.getString("jmni_guardaralts.text")); // NOI18N
        jmni_guardaralts.setName("jmni_guardaralts"); // NOI18N
        jmni_guardaralts.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmni_guardaraltsActionPerformed(evt);
            }
        });
        jMenu1.add(jmni_guardaralts);

        jmni_guardaorecep.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F7, 0));
        jmni_guardaorecep.setText(resourceMap.getString("jmni_guardaorecep.text")); // NOI18N
        jmni_guardaorecep.setName("jmni_guardaorecep"); // NOI18N
        jmni_guardaorecep.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmni_guardaorecepActionPerformed(evt);
            }
        });
        jMenu1.add(jmni_guardaorecep);

        jmni_salir.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.ALT_MASK));
        jmni_salir.setIcon(resourceMap.getIcon("jmni_salir.icon")); // NOI18N
        jmni_salir.setText(resourceMap.getString("jmni_salir.text")); // NOI18N
        jmni_salir.setName("jmni_salir"); // NOI18N
        jmni_salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmni_salirActionPerformed(evt);
            }
        });
        jMenu1.add(jmni_salir);

        jMenuBar1.add(jMenu1);

        jMenu2.setText(resourceMap.getString("jMenu2.text")); // NOI18N
        jMenu2.setName("jMenu2"); // NOI18N

        jmni_escape.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0));
        jmni_escape.setText(resourceMap.getString("jmni_escape.text")); // NOI18N
        jmni_escape.setName("jmni_escape"); // NOI18N
        jmni_escape.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmni_escapeActionPerformed(evt);
            }
        });
        jMenu2.add(jmni_escape);

        jMenuBar1.add(jMenu2);

        jMenu3.setText(resourceMap.getString("jMenu3.text")); // NOI18N
        jMenu3.setName("jMenu3"); // NOI18N

        jmni_ayuda.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK));
        jmni_ayuda.setIcon(resourceMap.getIcon("jmni_ayuda.icon")); // NOI18N
        jmni_ayuda.setText(resourceMap.getString("jmni_ayuda.text")); // NOI18N
        jmni_ayuda.setName("jmni_ayuda"); // NOI18N
        jMenu3.add(jmni_ayuda);

        jmni_sugerencias.setText(resourceMap.getString("jmni_sugerencias.text")); // NOI18N
        jmni_sugerencias.setName("jmni_sugerencias"); // NOI18N
        jmni_sugerencias.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmni_sugerenciasActionPerformed(evt);
            }
        });
        jMenu3.add(jmni_sugerencias);

        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jpn_encabezado, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jpn_cuerpo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jpn_encabezado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jpn_cuerpo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtn_guardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_guardarActionPerformed
        // TODO add your handling code here:
       
        ResultSet rs = null;
        float cantidad=0,totalpiezas=0;
        int nobjetotabla=this.jtb_insumos.getRowCount();
        int fi=0,controlfolio=0,error=0;
        
        String cadenafilas="{'", arreglo_articulos[]=null;
        JPasswordField pwd = new JPasswordField(10);
        this.quitarfotosestereporte();
        //lanso la confirmacion de password
        int action = JOptionPane.showConfirmDialog(null, pwd,"Contraseña:(Use Tab p/moverse o Mause)",JOptionPane.OK_CANCEL_OPTION);
        if(action < 0) {
            JOptionPane.showMessageDialog(null,"No se realiza Proceso, Gracias");
        } else {
            //comparo si la contraseña es apropiada
            if(variables_global.getPassword().equals(String.valueOf(pwd.getPassword()))) {//inicia trabajo para actualizar diferencias
               
                
                for(fi=0;fi<nobjetotabla;fi++) {
                    
                        try{
                            cantidad = Float.valueOf(this.jtb_insumos.getValueAt(fi, 3).toString()).floatValue();
                            totalpiezas+=cantidad;
                        }catch (NumberFormatException nfe) {
                            cantidad=0;
                            error=1;
                        }
                    // System.out.println("cachar error"+cadenafilas);
                    if (cantidad > 0)
                        {
                            cadenafilas+=""+this.jtb_insumos.getValueAt(fi, 3).toString()+":"+this.jtb_insumos.getValueAt(fi, 0).toString()+":"+this.jtb_insumos.getValueAt(fi, 4)+""+"\n";
                        }
                
                   

                }//fin del for

                    //System.out.println(s);
                //arreglo_articulos=cadenafilas.split(":");
        if ( (totalpiezas > 0) && (error==0) )
              {
                if(JOptionPane.showConfirmDialog(null, "Documento sera Guardado. Estan correcto sus Datos?")==0)
                    {
                        this.quitardescripcion();
                        java.util.Vector arreglodearticulos=this.jtable_modelo.getDataVector();

                        String articulos_papostgresql=arreglodearticulos.toString();
                        articulos_papostgresql=articulos_papostgresql.replace('[','{');
                        articulos_papostgresql=articulos_papostgresql.replace(']','}');
                        articulos_papostgresql=articulos_papostgresql.replace("null",".");

                        String arreglo_clie[]=this.jcmbx_tiendaclie.getSelectedItem().toString().split(":");
                        String arreglo_depa[]=this.jcmbx_depa.getSelectedItem().toString().split(":");
                        String arreglo_alma[]=this.jcmbx_almacenes.getSelectedItem().toString().split(":");
                        String arreglo_tipoinsu[]=this.jcbx_tiposinsumos.getSelectedItem().toString().split(":");
                        String arreglo_empleadoasigna[]=this.jcbx_empleados.getSelectedItem().toString().split(":");

                        String texto="select * from x1distribucion_insumos_salidas_insert('"+arreglo_clie[0]+"','"+this.fechaamericana(this.jdc_fechadocto.getDate())+"','"+this.jtf_observaciones.getText().trim().toUpperCase().replace(",", "").replace("{", "")+"','0','"+articulos_papostgresql+"',"+Integer.valueOf(arreglo_depa[0])+","+Integer.valueOf(arreglo_alma[0])+","+Integer.valueOf(arreglo_tipoinsu[0])+","+Integer.valueOf(arreglo_empleadoasigna[0])+")";
                        System.out.println(texto);
                        rs=x.sieuno_executediversosv2(texto,variables_global.getconexiongral());
                        try {
                                while (rs.next())
                                    {
                                        controlfolio=rs.getInt(1);
                                        if (rs.getInt(1) > 0)
                                                {
                                                    JOptionPane.showMessageDialog(null,"Requisicion Correcta, Gracias", "Sistema Integral(Requisicion Insumos) : Confirmacion",1);
                                                    this.imprimir(1,1,controlfolio);
                                                }
                                            else
                                                {
                                                    JOptionPane.showMessageDialog(null," Error Verifique sus Cantidades", "Sistema Integral(requisicion Insumos) : Error",1);
                                                }
                                     }

                                } catch(Exception e)
                                   {
                                        System.out.println(e.getMessage());
                                        JOptionPane.showMessageDialog(null," Recepcion Incorrecta ", "Sistema Integral(Requisicion Insumos) : Error",1);
                                   }

 
                    //this.btn_guardar.setVisible(false);
                    }//fin del if qu confirmo guardar diferencia
                  }
              else
                    {
                        JOptionPane.showMessageDialog(null,"por Favor Verifique que Las Cantidades Sean Numericas");
                    }
            } 
            else
                {
                    JOptionPane.showMessageDialog(null,"por Favor teclee su contraseña coreectamente, verifique mayusculas en teclado");
                }

        }

}//GEN-LAST:event_jbtn_guardarActionPerformed

    private void jbtn_salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_salirActionPerformed

        // TODO add your handling code here:
        //
        //x.cierraConexion();
        if(JOptionPane.showConfirmDialog(null, "Desea Salir?")==0)
              {
              this.dispose();
              }
        
}//GEN-LAST:event_jbtn_salirActionPerformed

    private void jbtn_helpayudameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_helpayudameActionPerformed
        // TODO add your handling code here:
        this.ayuda();
}//GEN-LAST:event_jbtn_helpayudameActionPerformed

    private void jcbx_tiposinsumosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbx_tiposinsumosActionPerformed
        // TODO add your handling code here:
        int indeceta=this.jcbx_tiposinsumos.getSelectedIndex();
        if  ((indeceta > 0) || (controlcombo > 0))  {
            if(JOptionPane.showConfirmDialog(null, "Estan Correctos sus Datos?")==0) {
                controlcombo=1;
                String arreglo_tipoinsumos[]=null;
                arreglo_tipoinsumos=this.jcbx_tiposinsumos.getSelectedItem().toString().split(":");
            this.cargar_insumos(Integer.valueOf(arreglo_tipoinsumos[0]));
            }

        }
        else
            {
             
            }
     
    }//GEN-LAST:event_jcbx_tiposinsumosActionPerformed
private String fechaamericana(Date fe) {
       SimpleDateFormat formateadorestaeuropa = new SimpleDateFormat("yyyy-MM-dd");
       String cadenafecha="";
       cadenafecha= formateadorestaeuropa.format(fe);
       return cadenafecha;

    }


    private void jmni_salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmni_salirActionPerformed
        // TODO add your handling code here:

        this.jbtn_salirActionPerformed(evt);
    }//GEN-LAST:event_jmni_salirActionPerformed

    private void jmni_sugerenciasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmni_sugerenciasActionPerformed
        // TODO add your handling code here:
        this.crearcomentario();
    }//GEN-LAST:event_jmni_sugerenciasActionPerformed

    private void jmni_guardaraltsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmni_guardaraltsActionPerformed
        // TODO add your handling code here:
        this.jbtn_guardarActionPerformed(evt);
        
    }//GEN-LAST:event_jmni_guardaraltsActionPerformed

    private void jmni_guardaorecepActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmni_guardaorecepActionPerformed
        // TODO add your handling code here:
        this.jbtn_guardarActionPerformed(evt);
    }//GEN-LAST:event_jmni_guardaorecepActionPerformed

    private void jcb_verfotosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcb_verfotosActionPerformed
        // TODO add your handling code here:
        if(this.jcb_verfotos.isSelected()==true) {
            this.verfotosestereporte();
        } else {
            this.quitarfotosestereporte();
        }

    }//GEN-LAST:event_jcb_verfotosActionPerformed

    private void jmni_escapeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmni_escapeActionPerformed
        // TODO add your handling code here:
        this.jbtn_salirActionPerformed(evt);
    }//GEN-LAST:event_jmni_escapeActionPerformed
 private void verfotosestereporte()
    {
     int numerofilas=this.jtable_modelo.getRowCount();
     this.cambiartamanofilas();
             for(int i = 0 ;i < numerofilas; i++)
                {
                      jtable_modelo.setValueAt("<html><head></head><body><p style=\"margin-top: 0\"><img src=\"http://"+variables_global.getHost()+"/javaweb/insumos/"+jtable_modelo.getValueAt(i, 0).toString()+".JPG\" width=\"180\" height=\"120\" border=\"0\" alt=\"Foto\"></img></p></body></html>", i,5);
                }
    }

 private void quitardescripcion()
    {
     int numerofilas=this.jtable_modelo.getRowCount();
    String punto="",comas="",imagen="";

             for(int i = 0 ;i < numerofilas; i++)
                {

                      comas=jtable_modelo.getValueAt(i, 1).toString().replace(",", "");
                      jtable_modelo.setValueAt(comas, i,1);
                      
                      punto=jtable_modelo.getValueAt(i, 4).toString().replace(".", "")+".";
                      jtable_modelo.setValueAt(punto, i,4);

                      imagen=jtable_modelo.getValueAt(i, 5)+".";
                      jtable_modelo.setValueAt(imagen, i,5);
                }
    }

void cambiartamanofilas()
 {
     //limpiar la tabla


       int numerofilas=this.jtable_modelo.getRowCount();

             for(int i = 0 ;i < numerofilas; i++)
                {
                     jtb_insumos.setRowHeight(i, 140);
                }
  }
 private void quitarfotosestereporte()
    {
     int numerofilas=this.jtable_modelo.getRowCount();

             for(int i = 0 ;i < numerofilas; i++)
                {
                      jtable_modelo.setValueAt("", i,5);
                      jtb_insumos.setRowHeight(i, 15);
                }

           //
    }
    private  void ayuda()
            {
                String punto1=" 1.-Detalle de Recepcion de Mercancia, cada opcion se autodescribe brevemente\n";
                String punto2=" 2.- Cada Boton tiene Una letra Resaltada el cual indica su metodo abreviado uselo si desea mayor rapides ( ejemplo Alt+a tendra ayuda automaticamente)\n";
                String punto3=" 3.- la opcion guardar esta activada para Recepcionar este documento Incluyendo Diferencias si no ingresa diferencias, el sistema guardara el documento como correcto\n";
                JOptionPane.showMessageDialog(null,punto1+punto2+punto3, "Sistema Integral(Detalle Recepcion) : Ayuda",1);
            }
private void LimpiarJTable()
 {
     //limpiar la tabla
    while(jtable_modelo.getRowCount()>0)jtable_modelo.removeRow(0);
 }
private void crearcomentario()
          {
                 String retorno="";

        String comentario=JOptionPane.showInputDialog("Ingresa Tu Sugerencia o Comentario:");
        if (comentario.length()>0)
        {
            rs = x.sieuno_executediversos("select * from x1distribucion_bitacorainserta('"+comentario+"', 'Insumos Requisicion');");
            try
            {

               while (rs.next())
                    {
                         retorno=rs.getString(1);
                   }
             }
            catch(Exception e)
            {
                System.out.println(e.getMessage());
            }
            if (retorno.equals("1"))
              {
                JOptionPane.showMessageDialog(null,"Gracias Tu comentario ha sido guardado", "Sistema Integral Comentarios",1);

              }

      }
    }

private String  fechaeuropea(Date fecha) {



       SimpleDateFormat formateadorestaeuropa = new SimpleDateFormat("dd-MM-yyyy");
       String cadenafecha="";

       cadenafecha= formateadorestaeuropa.format(fecha);
       return cadenafecha;

    }
    private void imprimir(int pag,float ptotal,int folio)
    {

     java.util.Date fechahoya=new Date();

     this.objimpresora=new insumos_salidas_imprimir();

     this.objimpresora.setOneItem_cadenas_a_imprimir("Requisicion Insumos");
     //this.objimpresora.setOneItem_cadenas_a_imprimir("Fecha:"+this.+"");
     this.objimpresora.setOneItem_cadenas_a_imprimir("Fecha:"+this.fechaeuropea(this.jdc_fechadocto.getDate())+"");
     this.objimpresora.setOneItem_cadenas_a_imprimir("Folio Tienda:"+folio+"");
     this.objimpresora.setOneItem_cadenas_a_imprimir("Status Documento:"+"Requisicion"+"");
     this.objimpresora.setOneItem_cadenas_a_imprimir("Cliente o Tienda:"+this.jcmbx_tiendaclie.getSelectedItem()+"");
     this.objimpresora.setOneItem_cadenas_a_imprimir("Consignado A:"+this.jcbx_empleados.getSelectedItem()+"");
     this.objimpresora.setOneItem_cadenas_a_imprimir("Observaciones:"+this.jtf_observaciones.getText()+"");
     this.objimpresora.setOneItem_cadenas_a_imprimir("*");
     this.objimpresora.setOneItem_cadenas_a_imprimir("paginas:"+ pag + " de "+ptotal+"");
     this.objimpresora.setOneItem_cadenas_a_imprimir("Responsalbe Almacen: ______________");
     this.objimpresora.setOneItem_cadenas_a_imprimir("Empaco: ______________");
     this.objimpresora.setOneItem_cadenas_a_imprimir("Recibio: ______________");
     this.objimpresora.setOneItem_cadenas_a_imprimir("..");
     this.objimpresora.setOneItem_cadenas_a_imprimir("..");
     this.objimpresora.setOneItem_cadenas_a_imprimir("..");
     this.objimpresora.setOneItem_cadenas_a_imprimir("..");
     this.objimpresora.setOneItem_cadenas_a_imprimir("..");
     this.objimpresora.setOneItem_cadenas_a_imprimir("..");
     this.objimpresora.setOneItem_cadenas_a_imprimir("..");
     this.objimpresora.setOneItem_cadenas_a_imprimir("*");
     this.objimpresora.setObjeto_tabla(jtb_insumos);
     this.objimpresora.imprimir_all(2,pag);
    }
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                insumos_salidas_agregar dialog = new insumos_salidas_agregar(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbtn_guardar;
    private javax.swing.JButton jbtn_helpayudame;
    private javax.swing.JButton jbtn_salir;
    private javax.swing.JCheckBox jcb_verfotos;
    private javax.swing.JComboBox jcbx_empleados;
    private javax.swing.JComboBox jcbx_tiposinsumos;
    private javax.swing.JComboBox jcmbx_almacenes;
    private javax.swing.JComboBox jcmbx_depa;
    private javax.swing.JComboBox jcmbx_tiendaclie;
    private com.toedter.calendar.JDateChooser jdc_fechadocto;
    private javax.swing.JMenuItem jmni_ayuda;
    private javax.swing.JMenuItem jmni_escape;
    private javax.swing.JMenuItem jmni_guardaorecep;
    private javax.swing.JMenuItem jmni_guardaralts;
    private javax.swing.JMenuItem jmni_salir;
    private javax.swing.JMenuItem jmni_sugerencias;
    private javax.swing.JPanel jpn_cuerpo;
    private javax.swing.JPanel jpn_encabezado;
    private javax.swing.JTable jtb_insumos;
    private javax.swing.JTextField jtf_observaciones;
    // End of variables declaration//GEN-END:variables
private insumos_salidas_imprimir objimpresora;
}
